package com.yangrong.thread.chapter1;

/**
 * 
 * @author YangRong
 * @date 2020年5月20日
 */
public class TryConcurrency {

	public static void main(String[] args) {
		Thread thread1 = new Thread() {
			public void run() {
				redFromDateBase();
			};
		};
		
		Thread thread2 = new Thread() {
			public void run() {
				writeDateToFile();
			};
		};
		
		thread1.start();
		thread2.start();
		
		Thread thread3 = new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
			}
		});
		
		thread3.start();
	}

	private static void redFromDateBase() {
		// read data from database and handle it.
		try {
			println("Begin read data from db.");
			Thread.sleep(1000 * 10L);
			println("Read data done and start handle it.");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		println("The data handle finish and successfully.");
	}

	private static void writeDateToFile() {
		try {
			println("Begin write data to file.");
			Thread.sleep(2000 * 10L);
			println("Write data done and start handle it.");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		println("The data handle finish and successfully.");
	}

	private static void println(String message) {
		System.out.println(message);
	}

}